<!--
 * @Author: wrh123 482597539@qq.com
 * @Date: 2024-01-16 09:34:03
 * @LastEditors: wrh123 482597539@qq.com
 * @LastEditTime: 2024-01-22 22:10:49
 * @FilePath: /vue-admin/src/views/assessment/components/addPend.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->

<template>
  <div class="PendingBtn">
    <el-dialog title="挑战申请" :visible="handDialogVisible" width="30%" :before-close="handleClose">
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px">
        <el-form-item prop="applyResult" label="申请结果">
          <el-select v-model="ruleForm.applyResult" size="mini">
            <el-option v-for="item in sponsorship" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="ruleForm.applyResult === 1" prop="accountId" label="下发账号">
          <el-select v-model="ruleForm.accountId" size="mini" @focus="getChallengeApplication">
            <el-option v-for="item in accountNumber" :key="item.id" :label="item.accountNumber" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="ruleForm.applyResult === 2" label="备注" prop="applyFailReason">
          <el-input v-model="ruleForm.applyFailReason" size="mini" />
        </el-form-item>
        <el-form-item v-if="ruleForm.applyResult === 1" label="备注">
          <el-input v-model="ruleForm.applyFailReason" size="mini" />
        </el-form-item>
        <el-form-item>
          <el-row type="flex" justify="end" style="margin-top: 10px;">
            <el-button size="mini" @click="handleClose">取 消</el-button>
            <el-button size="mini" type="primary" @click="btnOK">保存</el-button>
          </el-row>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getChallengeApplication, handleApply, handleApplyManual } from '@/api/assessment'

export default {
  name: 'VueAdminHandMovement',
  props: {
    handDialogVisible: {
      default: false,
      type: Boolean
    },
    dialogId: {
      default: null,
      type: Number
    },
    table: {
      type: Object,
      default: null,
    },

  },
  data() {
    return {
      ruleForm: {
        applyFailReason: null,
        applyResult: null,
        accountId: null, // 申请账号
        id: null
      },
      rules: {
        applyFailReason: [
          { required: true, message: '备注不可以为空', trigger: 'blur' }
        ],
        applyResult: [
          { required: true, message: '申请结果不可以为空', trigger: 'change' }
        ],
        accountId: [
          { required: true, message: '下发账号不可以为空', trigger: 'change' }
        ]
      },
      sponsorship: [
        { id: 1, name: '同意' },
        { id: 2, name: '驳回' }
      ],
      data: {}, // 申请账号回显参数
      accountNumber: [], // 挑战账号列表
    }
  },
  watch: {
    dialogId(old, val) {
      this.ruleForm.id = old
    },
    table(val) {
      this.data = val
    },
  },

  mounted() {
  },

  methods: {
    // 取消
    handleClose() {
      this.$refs.ruleForm.resetFields()
      this.$emit('update:handDialogVisible', false)
    },
    /**
     * @author 焦延龙 <19131965027@163.com>
     * @description 回显账号
     * @date 2024/3/12
     */
    async getChallengeApplication() {
      console.log("dddddd", this.table)
      const res = await getChallengeApplication(this.table)
      this.accountNumber = res
    },

    // 确定
    async btnOK() {
      await this.$refs.ruleForm.validate()
      const res = await handleApplyManual(this.ruleForm)
      console.log(res)
      this.$emit('refresh')
      this.handleClose()
    }
  }
}
</script>

<style lang="scss" scoped></style>
